package com.yixing.demo.mapper;

import com.yixing.demo.model.UserInfo;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface UserInfoMapper {
    @Select("select username, `password`, age, gender, phone, delete_flag," +
            " create_time, update_time from userinfo")
    List<UserInfo> queryAllUser();

    @Select("select * from userinfo where id = #{id} and delete_flag = #{deleteFlag}")
    UserInfo queryInfoByParma(@Param("id")Integer id, @Param("deleteFlag")Integer deleteFlag);

    @Options(useGeneratedKeys = true, keyProperty = "id")
    @Insert("insert into userinfo (username, `password`, age, gender, phone)" +
            " values (#{username}, #{password}, #{age}, #{gender}, #{phone})")
    Integer insertUser(UserInfo userInfo);

    @Delete("delete from userinfo where id = #{id}")
    Integer deleteUser(@Param("id")Integer id);

    @Update("update userinfo set username = #{username}, `password` = #{password}," +
            " age = #{age} where id = #{id}")
    Integer updateUser(UserInfo userInfo);
}
